﻿using System.Collections;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsMobile.PocketOutlook;
using PlaxoSyncWM;
using Contact=Microsoft.WindowsMobile.PocketOutlook.Contact;

namespace TestPlaxoSyncWM {
    [TestClass]
    public class TestIdDelta {
        #region Additional test attributes

        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //

        #endregion

        public IdDeltas idDeltas;
        public static MobileSettings ms = new MobileSettings();
        public OutlookSession os;
        public ContactCollection collectionOfContacts;
        
        [TestInitialize]
        public void InitializeMe() {
            MobileContactsFile mcf = new MobileContactsFile();
            if (!mcf.mobileContactsFileExists())
            {
                mcf.create();
            }

            idDeltas = new IdDeltas();
            os = new OutlookSession();
            collectionOfContacts = os.Contacts.Items.Restrict("[FirstName]=\"Karen\"");
            ArrayList editedIDs = new ArrayList();
            editedIDs.Clear();
            foreach (Contact editedContact in collectionOfContacts) {
                editedContact.MobileTelephoneNumber = "07940904212";
                editedContact.Update();
            }
            collectionOfContacts = os.Contacts.Items.Restrict("[FirstName]=\"Eugene\"");
            ArrayList deletedContacts = new ArrayList();
            deletedContacts.Clear();
            foreach (Contact deletedContact in collectionOfContacts) {
                deletedContact.Delete();
            }
        }

        [TestMethod]
        public void testIdDeletedContacts() {
            Assert.AreEqual(1, (idDeltas.IdDeletedContacts().Count));
        }

        [TestMethod]
        public void testIdNewContactsOnDevice() {
            Assert.AreEqual(0, idDeltas.IdNewContactsOnDevice().Count);
        }

        [TestMethod]
        public void testIdEditedContacts()
        {
            Assert.AreEqual(1, idDeltas.IdEditedContacts().Count);
        }
    }
}